package cn.tedu.order.tcc;

import cn.tedu.order.entity.Order;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

/**
 * Seata的TCC操作接口
 * 添加TCC的三个方法
 */
@LocalTCC
public interface OrderTccAction {
    //第一阶段预留资源的注解,第二参数：第二阶段的方法名有默认属性，默认commit,rollback
    //第一阶段需要手动调用

    @TwoPhaseBusinessAction(name = "OrderTccAction")
    Boolean prepareCreatOrder(BusinessActionContext ctx,
                              @BusinessActionContextParameter(paramName = "orderId") Long orderId,
                              @BusinessActionContextParameter(paramName = "userId") Long userId,
                              @BusinessActionContextParameter(paramName = "productId") Long productId,
                              @BusinessActionContextParameter(paramName = "count") Integer count,
                              @BusinessActionContextParameter(paramName = "money") BigDecimal money);//传递数据用的
    //第二阶段,需要seata自动执行
    boolean commit(BusinessActionContext ctx);
    boolean rollback(BusinessActionContext ctx);
}
